#include "filterbutton.h"

FilterButton::FilterButton()
{
    Gtk::Image *closeicon = Gtk::manage (new Gtk::Image ("images/close.png"));
    m_closebutton.add(*closeicon);
    //m_closebutton.set_label("X");
    //m_closebutton.modify_bg(Gtk::STATE_NORMAL,Gdk::Color("grey"));
    //m_closebutton.modify_bg(Gtk::STATE_SELECTED,Gdk::Color("green"));
    m_closebutton.modify_bg(Gtk::STATE_PRELIGHT,Gdk::Color("white"));
    //m_closebutton.modify_bg(Gtk::STATE_INSENSITIVE,Gdk::Color("orange"));
    //m_closebutton.modify_bg(Gtk::STATE_ACTIVE,Gdk::Color("white"));

    //to make the button zoomed as the requested size
    m_closebutton.set_size_request(-1,-1);

    Gtk::VBox *vbox=Gtk::manage(new Gtk::VBox());
    vbox->pack_start(m_closebutton,false,false,0);
    Gtk::Alignment *align=Gtk::manage(new Gtk::Alignment(Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, 0.0, 0.0));
    align->add(*vbox);
    //vbox->pack_start(*hbox,false,false,0);
    pack_end(*align,false,false,0);

    Gtk::HBox *hbox=Gtk::manage(new Gtk::HBox());
    hbox->pack_start(m_icontype);
    hbox->pack_start(m_text);
    m_eventbox.add(*hbox);
    pack_start(m_eventbox,false,false,0);

    m_closebutton.signal_clicked().connect(sigc::mem_fun(*this,&FilterButton::on_button_close));
    m_closebutton.signal_enter().connect(sigc::mem_fun(*this,&FilterButton::on_button_enter));
    m_closebutton.signal_leave().connect(sigc::mem_fun(*this,&FilterButton::on_button_leave));
    show_all_children();
}

FilterButton::~FilterButton()
{
}
void FilterButton::set_filter(const sdms::Filter& f)
{
    m_filter=f;
}
void FilterButton::set_text(const Glib::ustring t)
{
    m_text.set_text(t);
}
void FilterButton::on_button_close()
{
    std::cout<<"on button close"<<std::endl;
    std::cout<<"sql: "<<m_filter.get_sql()<<std::endl;
    m_signal_closed.emit(m_filter.get_sql());
    hide();
}
void FilterButton::set_icontype(IconType it)
{
    switch(it)
    {
    case TAG:
        m_icontype.set(utils::get_data_dir()+"images/tag-icon.png");
        //m_icontype.set_size_request(20,20);
        break;
    case PUBLISHER:
        m_icontype.set(utils::get_data_dir()+"images/publisher-icon.png");
        break;
    case WRITING:
        m_icontype.set(utils::get_data_dir()+"images/writing-icon.png");
        break;
    default:
        m_icontype.set(utils::get_data_dir()+"images/filter-icon.png");
        break;
    }
}
FilterButton::SignalClosed FilterButton::signal_closed()
{
    return m_signal_closed;
}
void FilterButton::on_button_enter()
{
    m_eventbox.modify_bg(Gtk::STATE_NORMAL,Gdk::Color("grey"));
}
void FilterButton::on_button_leave()
{
    m_eventbox.unset_bg(Gtk::STATE_NORMAL);
}
